package com.jic.market.impl.overlay;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.entity.overlay.OverlayPromotionInfo;
import com.jic.market.mapper.overlay.OverlayPromotionInfoMapper;
import com.jic.market.service.overlay.OverlayPromotionInfoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 叠加规则活动信息表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-20 04:52:58
 */
@Service
public class OverlayPromotionInfoServiceImpl implements OverlayPromotionInfoService {

    @Autowired
    private OverlayPromotionInfoMapper overlayPromotionInfoMapper;

    @Override
    public long insert(OverlayPromotionInfo overlayPromotionInfo) {
        long flag = overlayPromotionInfoMapper.insert(overlayPromotionInfo);
        return flag;
    }

    @Override
    public long delete(String id) {
        return overlayPromotionInfoMapper.delete(id);
    }

    @Override
    public long update(OverlayPromotionInfo overlayPromotionInfo) {
        return overlayPromotionInfoMapper.update(overlayPromotionInfo);
    }

    @Override
    public OverlayPromotionInfo queryByPrimaryKey(Long id) {
        return overlayPromotionInfoMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<OverlayPromotionInfo> query(OverlayPromotionInfo overlayPromotionInfo) {
        return overlayPromotionInfoMapper.query(overlayPromotionInfo);
    }

    @Override
    public PageResult<OverlayPromotionInfo> queryPage(OverlayPromotionInfo overlayPromotionInfo, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<OverlayPromotionInfo> list = overlayPromotionInfoMapper.queryPage(startIndex, pageQuery.getLimit(), overlayPromotionInfo);
        long count = overlayPromotionInfoMapper.queryPageCount(overlayPromotionInfo);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}